package com.csy.ocmis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.csy.ocmis.entity.Cashier;
import com.csy.ocmis.entity.Pharmacy;
import com.csy.ocmis.entity.ReportVo;
import com.csy.ocmis.mapper.CashierMapper;
import com.csy.ocmis.service.ICashierService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author csy
 * @since 2020-11-30
 */
@Service
public class CashierServiceImpl extends ServiceImpl<CashierMapper, Cashier> implements ICashierService {

    @Autowired
    private CashierMapper cashierMapper;
    @Override
    public List<ReportVo> selPer() {
        return cashierMapper.selPer();
    }

    @Override
    public Integer updchu(Cashier cashier) {
        return cashierMapper.updchu(cashier);
    }

    @Override
    public List<Cashier> selxiang(Integer perid) {
        QueryWrapper<Cashier> wrapper = new QueryWrapper<>();
        wrapper.eq("reportId",perid);
        wrapper.eq("state",1);
        wrapper.eq("mstate",0);
        wrapper.orderByDesc("cashier");
        return cashierMapper.selectList(wrapper);
    }


    @Override
    public Double selshoux(Integer perid) {
        QueryWrapper<Cashier> wrapper = new QueryWrapper<>();
        wrapper.eq("reportId",perid);
        wrapper.eq("state",1);
        wrapper.eq("mstate",0);
        SimpleDateFormat sdf1 = new SimpleDateFormat("y-MM-dd");
        String date = sdf1.format(new Date());
        wrapper.eq("ctime",date);
        wrapper.orderByDesc("cashier");
        List<Cashier> cashiers = cashierMapper.selectList(wrapper);
        Double sum = 0.0;
        for (Cashier cashier : cashiers) {
            sum+=cashier.getRepicetotal();
        }
        return sum;
    }

/**
 * 用户项目收费修改用户的项目收费状态
  */

    @Override
    public Integer updxiang(Integer perid) {
        QueryWrapper<Cashier> wrapper = new QueryWrapper<>();
        wrapper.eq("reportId",perid);
        wrapper.eq("mstate",0);
        Cashier cashier = new Cashier();
        cashier.setMstate(1);
        return cashierMapper.update(cashier,wrapper);
    }

//    项目检查页面查询用户所有要检查的项目
    @Override
    public List<Cashier> selcha(Integer perid) {
        QueryWrapper<Cashier> wrapper = new QueryWrapper<>();
        wrapper.eq("reportId",perid);
        wrapper.eq("state",1);
        wrapper.eq("ostate",1);
        wrapper.eq("mstate",1);
        wrapper.orderByDesc("cashier");
        return cashierMapper.selectList(wrapper);
    }

    @Override
    public List<Cashier> selpepci(Integer perid) {
        QueryWrapper<Cashier> wrapper = new QueryWrapper<>();
        wrapper.eq("reportId",perid);
        wrapper.eq("state",0);
        wrapper.orderByDesc("cashier");
        return cashierMapper.selectList(wrapper);
    }

    @Override
    public int seljiao(Integer reid) {
        QueryWrapper<Cashier> wrapper = new QueryWrapper<>();
        wrapper.eq("reportId",reid);
        wrapper.eq("mstate",0);
        wrapper.eq("state",1);
        return cashierMapper.selectCount(wrapper);
    }

    @Override
    public Integer selyi(Integer reid) {
        return cashierMapper.selyi(reid);
    }

    @Override
    public Integer selgong(Integer reid) {
        return cashierMapper.selgong(reid);
    }

    @Override
    public Double selch(Cashier cCashier) {
        return cashierMapper.selch(cCashier);
    }

    @Override
    public List<ReportVo> mohu(ReportVo reportVo) {
        return cashierMapper.mohu(reportVo);
    }

    @Override
    public int zong(Integer reid) {
        return cashierMapper.zong(reid);
    }
}
